using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using KS.Common;
using KS.Gantt;
using KS.Gantt.Dialogs.Controls;

namespace MiGuava
{
    public partial class ucResources : ucGridView
    {
        public ucResources()
        {
            InitializeComponent();

            GRD.AllowUserToAddRows = false;
            GRD.AllowUserToResizeRows = false;
            GRD.AutoGenerateColumns = false;
        }

        public override void InitData()
        {
            GRD.Columns.Clear();            

            this.DataSource = m_GanttControl.Resources;            

            // SetUp custom edit controls            

            // Text
            DataGridViewTextBoxColumn txtText = new DataGridViewTextBoxColumn();
            txtText.DataPropertyName = "Text";
            txtText.HeaderText = Properties.Resources.ColumnHeader_Text;
            txtText.Width = 240;
            GRD.Columns.Add(txtText);

            // ResourceType
            DataGridViewComboBoxColumn colResourceType = new DataGridViewComboBoxColumn();
            KS.Gantt.Dialogs.ComboBoxHelpers.FillComboEx(colResourceType, typeof(KS.Gantt.ResourceTypes));
            colResourceType.DataPropertyName = "ResourceType";
            colResourceType.Name = "ResourceType";
            colResourceType.HeaderText = Properties.Resources.ColumnHeader_ResourceType;
            colResourceType.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
            colResourceType.Width = 120;
            GRD.Columns.Add(colResourceType);

            // Role
            DataGridViewTextBoxColumn txtRole = new DataGridViewTextBoxColumn();
            txtRole.DataPropertyName = "Role";
            txtRole.HeaderText = Properties.Resources.ColumnHeader_Role;
            txtRole.Width = 160;
            GRD.Columns.Add(txtRole);

            // CostPerHour
            DataGridViewNumericUpDownColumn colCostPerHour = new DataGridViewNumericUpDownColumn();
            colCostPerHour.Name = "CostPerHour";
            colCostPerHour.DataPropertyName = "CostPerHour";
            colCostPerHour.HeaderText = Properties.Resources.ColumnHeader_CostPerHour;
            colCostPerHour.SortMode = DataGridViewColumnSortMode.Automatic;
            colCostPerHour.ReadOnly = false;
            colCostPerHour.DecimalPlaces = 2;
            colCostPerHour.ThousandsSeparator = true;
            colCostPerHour.Increment = 1;
            colCostPerHour.Minimum = 0;
            colCostPerHour.Maximum = Decimal.MaxValue;
            colCostPerHour.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            colCostPerHour.Width = 120;
            GRD.Columns.Add(colCostPerHour);

            // Description
            DataGridViewTextBoxColumn txtDescription = new DataGridViewTextBoxColumn();
            txtDescription.DataPropertyName = "Description";
            txtDescription.HeaderText = Properties.Resources.ColumnHeader_Description;
            txtDescription.Width = 240;
            GRD.Columns.Add(txtDescription);

            EnableControls();
        }

        protected override void mnuNew_Click(object sender, EventArgs e)
        {
            base.mnuNew_Click(sender, e);

            if (m_GanttControl == null)
                return;

            Program.CursorWait();
            KS.Gantt.Dialogs.ResourceEditDialog Dlg = new KS.Gantt.Dialogs.ResourceEditDialog();
            Dlg.Edit(m_GanttControl, null);
            Dlg.ShowDialog(this);
            Dlg.Dispose();
            Dlg = null;
        }

        protected override void mnuEdit_Click(object sender, EventArgs e)
        {
            base.mnuEdit_Click(sender, e);

            if (m_GanttControl == null || GRD.CurrentRow == null)
                return;

            GanttItem item = (GanttItem)GRD.CurrentRow.DataBoundItem;
            Program.CursorWait();
            m_GanttControl.EditItem(item);

            SelectGanttItem(item);
        }
    }
}
